package main.niit.servelet;

import com.google.gson.Gson;
import main.niit.Service.GetAll;
import main.niit.pojo.*;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

@WebServlet("/getinformation")
public class getinformationservlet extends HttpServlet{
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 设置请求和响应的编码格式
        req.setCharacterEncoding("utf-8");
        resp.setCharacterEncoding("utf-8");
        resp.setContentType("application/json");

        GetAll getAll = new GetAll();
        List<SessionData> list1= null;
        List<Top10Category> list2= null;
        List<top10_sessionData> list3= null;
        List<AreaTop3Product> list4= null;
        List<AdStat> list5= null;
        List<AdProvinceTop3> list6= null;
        try {
            list1 = getAll.get1();
            list2 = getAll.get2();
            list3 = getAll.get3();;
            list4 = getAll.get4();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        Gson gson = new Gson();
//        String json1 = gson.toJson(list1);
//        String json2 = gson.toJson(list2);
//        String json3 = gson.toJson(list3);
//        String json4 = gson.toJson(list4);
//        String json5 = gson.toJson(list5);
//        String json6 = gson.toJson(list6);

        List<Object> allData = new ArrayList<>();
        allData.addAll(list1);
        allData.addAll(list2);
        allData.addAll(list3);
        allData.addAll(list4);

        String json = gson.toJson(allData);
//
//        resp.getWriter().write(json1);
//        resp.getWriter().write(json2);
//        resp.getWriter().write(json3);
//        resp.getWriter().write(json4);
//        resp.getWriter().write(json5);
//        resp.getWriter().write(json6);
        resp.getWriter().write(json);
    }
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req,resp);
    }
}

